package com.gitee.yannzh.rune.common.json.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;

public class BigDecimalSerializer extends JsonSerializer<BigDecimal>{

    public static final BigDecimalSerializer INSTANCE = new BigDecimalSerializer();
    @Override
    public void serialize(BigDecimal o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        DecimalFormat format = new DecimalFormat("#0.00");

//        super.serialize(value, gen, provider);
        jsonGenerator.writeNumber(format.format(o));
    }
}
